package com.formiaomiao.demain.controller;

import com.formiaomiao.demain.model.DiscussBean;
import com.formiaomiao.demain.service.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/discuss")
public class DiscussController {

    @Autowired
    DiscussService discussService;

    /**
     * 发表评论
     *
     * @param comid
     * @param discussdata
     * @param fromid
     * @param toid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insertDiscuss")
    private Object InsertDiscuss(@RequestParam(name = "comid", required = false) String comid,
                                 @RequestParam(name = "discussdata", required = false) String discussdata,
                                 @RequestParam(name = "fromid", required = false) Integer fromid,
                                 @RequestParam(name = "toid", required = false) Integer toid) {
        DiscussBean discussBean = new DiscussBean();
        discussBean.setComid(comid);
        discussBean.setDiscussdata(discussdata);
        discussBean.setFromid(fromid);
        discussBean.setToid(toid);
        discussBean.setDiscussdate(String.valueOf(System.currentTimeMillis()));
        return discussService.InsertDiscuss(discussBean);
    }

    /**
     * 删除评论
     *
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteDiscuss")
    private Object DeleteDiscuss(@RequestParam(name = "id", required = false) Integer id) {
        DiscussBean discussBean = new DiscussBean();
        discussBean.setId(id);
        return discussService.DeleteDiscuss(discussBean);
    }

    /**
     * 查询评论
     *
     * @param comid
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectDiscuss")
    private Object SelectDiscuss(@RequestParam(name = "comid", required = false) String comid,
                                 @RequestParam(name = "pageNum", required = false) Integer pageNum,
                                 @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return discussService.SelectDiscuss(comid, pageNum, pageSize);
    }

}
